#include "Base.h"

VOID InitBigValue(ULONG ulInitValue, BIGVALUE* pbvResult)
{
    BYTE* pucTemp = NULL;
    NewBigValue(pbvResult, sizeof(ulInitValue));
	pucTemp = pbvResult->pucBuff;
	*(pucTemp++) = (BYTE)(ulInitValue & 0xFF);
	*(pucTemp++)= (BYTE)((ulInitValue >> 8) & 0xFF);
	*(pucTemp++)= (BYTE)((ulInitValue >> 16) & 0xFF);
	*(pucTemp)   = (BYTE)((ulInitValue >> 24) & 0xFF);
}

VOID NewBigValue(BIGVALUE* pbvResult, ULONG ulByteCount)
{
    pbvResult->ulByteCount = ulByteCount;
	if(pbvResult->bUsed)
	{
	    Free(pbvResult->pucBuff);
	}
	pbvResult->pucBuff = (BYTE*)Malloc(pbvResult->ulByteCount);
	Memset(pbvResult->pucBuff, 0, pbvResult->ulByteCount);
	pbvResult->bUsed = TRUE;
}

VOID ResetBigValue(BIGVALUE* pbvResult)
{
	if(pbvResult->bUsed)
	{
	    Free(pbvResult->pucBuff);
	}
	Memset(pbvResult, 0, sizeof(BIGVALUE));
}

VOID CopyBigValue(BIGVALUE bvSrc, BIGVALUE* pbvDst)
{
    if(pbvDst->bUsed)
    {
        Free(pbvDst->pucBuff);
    }
    Memcpy(pbvDst, &bvSrc, sizeof(BIGVALUE));
}

VOID PrintBigValue(BIGVALUE bvValue)
{
    BYTE* pucTemp = NULL;
    ULONG ulLoop = 0;
    BOOLEAN bHighBitZero = TRUE; 
    Print("Vlaue is 0x");
    for(ulLoop = 0; ulLoop < bvValue.ulByteCount; ulLoop++)
    {
        pucTemp = bvValue.pucBuff + (bvValue.ulByteCount - ulLoop - 1);
        if(bHighBitZero && (*pucTemp == 0))
        {
            continue;
        }
        bHighBitZero = FALSE;
        Print("%02x", *pucTemp);
    }
    if(bHighBitZero)
    {
        Print("00");
    }
    Print(".\n");
}




